
var confirmPassword = (rule,value,callback) =>{
          
    if(value !== this.regForm.password){
         callback(new Error('两次输入密码不一致!'));
     }else {
         callback();
     }
}
export default{
    namespaced:true,
    state:{
        userInfo:{
            token:'',
            profile:{},
            role:null
        },
        loginRule:{
            rules:{
                username:[{ required: true, message: '请输入用户名', trigger: 'blur' },
                          { min: 5, max: 12, message: '长度在 5 到 12 个字符', trigger: 'blur'}],
                password:[{ required: true, message: '请输入密码', trigger: 'blur' },
                          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur'}],
                 
                repeatPass:[{validator:confirmPassword,required:true,trigger:'blur'}],
                email:[{required:true,message:'请输入邮箱',trigger:'blur'}]         
            },
        }
    },
    mutations:{
        setUser(state,user){
            state.userInfo.profile = user.profile;
            state.userInfo.token = user.token;
            state.userInfo.role = user.role;
        },
        setProfile(state,profile){
            state.userInfo.profile = profile;
        },
        setRole(state,role){
            state.userInfo.role = role;
        },
 
    },
    actions:{
        setProfile(context,profile){
            context.commit('setProfile',profile)
        },
        // 修改密码

          
        
    },
    getters:{
        userData(state){
            return state.userInfo.profile||{};
        }
    }
}